import Base from 'models/base';

export default class AdvertisementForm extends Base {
  advertisementName = '';
  advertisementType = '';
  advertisementUrl = [];
  advertisementHref = '';
  advertisementSort = undefined;
  advertisementStatus = 1;

  constructor(advertisement) {
    super();

    if (advertisement === undefined) {
      return;
    }

    let fields = ['advertisementName', 'advertisementType', 'advertisementHref', 'advertisementSort', 'advertisementStatus'];
    this.initObject(advertisement, fields);

    let advertisementUrl = advertisement.advertisementUrl;
    this.advertisementUrl = [advertisementUrl];
    this.id = advertisement.advertisementId;
  }

  checkValid() {
    let fields = ['advertisementName', 'advertisementType', 'advertisementUrl', 'advertisementSort'];
    return this.checkRequired(fields);
  }

  getObject() {
    let postData = {};
    let fields = ['advertisementName', 'advertisementType', 'advertisementHref', 'advertisementSort', 'advertisementStatus'];
    this.setPostData(postData, fields, true);

    let advertisementUrl = this.advertisementUrl;
    postData.advertisementUrl = advertisementUrl[0];

    let id = this.id;
    if (id !== undefined) {
      postData.advertisementId = id;
    }

    return postData;
  }
}
